#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lwip/sockets.h"

int tcp_server_init(int port)
{
    int sfd = 0;
    struct sockaddr_in saddr;

    sfd = socket(AF_INET,SOCK_STREAM,0);
    
    memset(&saddr, 0, sizeof(struct sockaddr));
    saddr.sin_family  = AF_INET;
    saddr.sin_port    = htons(port);
    saddr.sin_addr.s_addr = INADDR_ANY;
    bind(sfd, (struct  socket*)&saddr, sizeof(struct sockaddr));

    listen(sfd,5);

    return sfd;
}

int tcp_server_accept(int sfd)
{
    int cfd = 0;
    struct  sockaddr_in caddr;
    memset(&caddr, 0, sizeof(struct sockaddr));
    int addrl = sizeof(struct sockaddr);
    cfd = accept(sfd , (struct sockaddr*)&caddr , &addrl);
    return cfd;
}